export default {
	get(url, params) {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title: '加载中...'
			})
			uni.request({
				url,
				data: params,
				success(response) {
					uni.hideLoading()
					if (response.statusCode === 200) {
						resolve(response.data)
					} else {
						reject(response.data)
					}
				},
				fail(error) {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: error.errMsg || '请求出错了'
					})
					reject(error)
				}
			})
		})
	},
	post(url, data) {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title: '加载中...'
			})
			uni.request({
				url,
				method: 'POST',
				data,
				header: {
					'content-type': 'application/json'
				},
				success(response) {
					uni.hideLoading()
					if (response.statusCode === 200) {
						resolve(response.data)
					} else {
						reject(response.data)
					}
				},
				fail(error) {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: error.errMsg || '请求出错了'
					})
					reject(error)
				}
			})
		})
	}
}
